<script>
const isAndroidClient = s => /Android/i.test(s) || /Adr/i.test(s);
const APP_ID = 'com.tnaot.newspro';
const GOOGLE_PLAY_SCHEME_URL = `market://details?id=${APP_ID}`;
const APPLE_STORE_URL = 'https://itunes.apple.com/us/app/tnaot/id1296073079';

export default {

  async asyncData(ctx) {
    if (process.server) {
      const userAgent = ctx.req.headers['user-agent'];
      const isAndroid = isAndroidClient(userAgent);
      const url = isAndroid ? GOOGLE_PLAY_SCHEME_URL : APPLE_STORE_URL;
      return ctx.redirect(url);
    } else {
      return ctx.redirect(`/${ctx.store.state.locale}/m/download`);
    }
  }
};
</script>
